home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / kommode.lua < prev    next >
Text File  |  2004-01-29  |  2KB  |  66 lines

  1. -- kommode state machine
  2. beginStateMachine()
  3.     
  4.     onMsg("buildMenu", function(msg)
  5.     
  6.         if (repairMenu()) then return end
  7.     
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         -- get character who initiated this action
  11.         local character = getStateObjectFromID(msg.sender);
  12.         if (character) then
  13.             -- get the pie menu buttons
  14.             local outfits = character.getOutfits();
  15.             for i = 1, getn(outfits) do
  16.                 local button;
  17.                 local outfit = outfits[i];
  18.                 if not enumCompare(outfit.getID(), character.getOutfit()) then
  19.                     --print("######### outfitname: "..outfit.getName().." - outfit - "..tostring(outfit.getID()));
  20.                     button = addPieMenuButton(outfit.getName(), "outfit", tostring(outfit.getID()));
  21.                 end
  22.                 -- button.addIcon("guiIconComfort");
  23.             end
  24.         end
  25.     end )
  26.     
  27.     -- change outfit
  28.     onMsg("outfit", function(msg)
  29.         -- get the game object server
  30.         local gameObjectServer = getGameObjectServer();
  31.         -- get character who initiated this action
  32.         local character = getStateObjectFromID(msg.sender);
  33.         -- walk to the closest action point
  34.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"change1", "change2"});
  35.         --local actionPoints = character.getFreeActionPoints(this, {"change1", "change2"});
  36.         if (actionPoint) then
  37.             -- get the walk state object
  38.             local wso = character.walkSO;
  39.             if (wso.walkToActionPoint(actionPoint)) then            
  40.                 -- notify current mission 
  41.                 character.sendMsg("outfit", gameObjectServer.mission);
  42.  
  43.                 print("walkToActionPoint true");
  44.                 -- create state machine contexts
  45.                 local wsoContext = StateMachineContext();
  46.                 -- store the action point
  47.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  48.                 -- store the outfit
  49.                 wsoContext.storeData("outfit", tonumber(msg.data));
  50.                 wso.queueStateMachine("kommodeChar.outfit", this, wsoContext);
  51.             else
  52.                 print("no path found for actionpoint " .. actionPoint.getName());
  53.                 -- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  54.                 -- sendMsg("emoThink", character.walkSO);
  55.                 instantAbort(character, EMOTICON_NOPATH, "emoThink");
  56.             end
  57.         else
  58.             print("no action point found");
  59.             -- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  60.             -- sendMsg("emoThink", character.walkSO);
  61.             instantAbort(character, EMOTICON_CANNOT, "emoThink");
  62.         end
  63.     end )
  64.             
  65. endStateMachine()
  66.